import React from 'react'
import { Table,Input,Button} from 'antd';
import axios from '../service.js'
class Account extends React.Component {
      constructor(props){
        super(props);
        this.state = { branch:"",alldata:[]};
        this.columns = [
          {
            title: '区域',
            dataIndex: 'region',
            key: 'region',
          },
          {
            title: '账号',
            dataIndex: 'account',
            key: 'account',
          },
          {
            title: '账号类型',
            dataIndex: 'type',
            key: 'type',
            width:400
          }];
          
      }
      componentDidMount(){
        this.init();
      }
      init=()=>{
           let _this=this;
           axios.post('/query/account',{branch:_this.state.branch}).then((response)=>{
               let data=response.data;
               let dataArr=[];
               for(let i in data){
                    dataArr.push({
                        key:i,
                        region:data[i]['region'],
                        account:data[i]['account'],
                        type:data[i]['usertype']
                    })
                    
               }
               //console.log(dataArr);
               _this.setState({alldata:dataArr});
               //console.log(this.state.alldata)
           })
           
      }
      query=()=>{
          this.init();
      }
      changevalue=(e)=>{
          let bra=e.target.value;
          this.setState({branch:bra});
      }
      render(){
        return (
           <div>
             <div style={{float:"right"}}>
                <Input id="queryinput" autoComplete="off" allowClear={true}  placeholder="请输入机构名称" onChange={event => this.changevalue(event)} onPressEnter={this.query}  style={{width:"200px",marginRight:"10px"}}/>
                <Button  onClick={this.query}>查询</Button>
              </div>
              <Table style={{paddingTop:50}} columns={this.columns} dataSource={this.state.alldata} />

              
           </div>
        )
      }
}
export default Account;